function HeadWriter(xhr, output) {
	
	var reqWritten = false;

	this.writeHead = function(h) {
		var hs = h.getAllHeaders();

		if(reqWritten || h.getStatusLine().substring(0,4) == "HTTP") {
			var o = output;
			o.writeLine(h.getStatusLine());

			for(var id in hs)
				o.writeLine(hs[id].getName() + ": " + hs[id].getValue());

			o.writeLine("");
		}
		else {
			var toks = h.getStatusLine().split(" ");

			xhr.open(toks[0], toks[1], true);

			for(var id in hs)
				xhr.setRequestHeader(hs[id].getName(), hs[id].getValue());

			reqWritten = true;
		}
	}
	
	this.close = function() {
		reqWritten = false;
	}
	
}
